﻿using System;
using System.Drawing;
using System.Windows.Forms;
using GraphDrawing.Model;
using GraphDrawing.View;

namespace GraphDrawing.Interface
{
    public class Presenter : IDropCallback, IDisposable
    {
        readonly IView view;
        readonly MyModel model;

        public IDragSourceController DragSourceController { get; private set; }
        public IDropTargetController DropTargetController { get; private set; }

        public Presenter()
        {
            model = new MyModel();
            view = new Form1(this);
            var controller = new DragDropController(view, this);
            DragSourceController = controller;
            DropTargetController = controller;
        }

        public void Run()
        {
            view.Initialize(model);
            Application.Run((Form) view);
        }

        public void Dispose()
        {
            view.Dispose();
        }

        void IDropCallback.OnDrop(IDataObject obj, Point point)
        {
            var id = (string) obj.GetData(typeof (string));
            model.PutBlock(id, point);
            view.UpdateView();
        }
    }
}